<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>Check</title>
</head>

<body>
    <?php
    session_start();
    function clearCookies()
    {
        setcookie("username", "", time() - 1);
        setcookie("password", "", time() - 1);
        echo "清除成功!";
    }
    function logout()
    {
        unset($_SESSION['isLogged']);
        echo "登出成功!";
    }
    if ($_GET['action'] == "login") {
        $username = $_POST['username'];
        $password = $_POST['password'];

        if ($username == 'admin' && $password == '123456') {
            echo "登录成功!";
            $_SESSION['isLogged'] = true;
            if (isset($_POST['check'])) {
                setcookie("username", $username, time() + 3600 * 24 * 7);
                setcookie("password", $password, time() + 3600 * 24 * 7);
            }
        } else {
            echo "登录失败!";
        }
    } else if ($_GET['action'] == "logout") {
        logout();
    } else if ($_GET['action'] == "clear") {
        clearCookies();
    }
    header("refresh:1;url=login.php");
    ?>
</body>